import { defineStore } from 'pinia';
import { ref } from 'vue';

import User from '../../user/user';
import AuthenticationService from '../services/authentication-service';

const useAuthenticationStore = defineStore('authentication', () => {
  const isAuthenticated = ref<boolean>(AuthenticationService.isAuthenticated);
  const currentUser = ref<User | null>(AuthenticationService.currentUser);
  const currentUsername = ref<string | null>(AuthenticationService.currentUsername);

  function changeIsAuthenticated(value: boolean) {
    isAuthenticated.value = value;
  }

  function changeCurrentUser(value: User | null) {
    currentUser.value = value
  }

  function changeCurrentUsername(value: string | null) {
    currentUsername.value = value;
  }

  return {
    isAuthenticated,
    currentUser,
    currentUsername,
    changeIsAuthenticated,
    changeCurrentUser,
    changeCurrentUsername,
  };
});

export default useAuthenticationStore;